import random

# 使用原始字符串（r'path'）避免转义字符问题
with open(r'D:\Users\project\python\实验4 文件操作\rand.txt', 'w', encoding='UTF-8') as file:
    for x in range(1000):
        rand = random.randint(0, 1000)
        file.write(str(rand))  # 将数字转换为字符串
        if x < 999:  # 如果不是最后一个数字，添加逗号
            file.write(",")

with open(r'D:\Users\project\python\实验4 文件操作\rand.txt', 'r', encoding='UTF-8') as file:
    content = file.read()
    nums = content.split(",")
    nums = [int(num) for num in nums]
    nums.sort()
    print(f"{nums}")

